import UserApi from "@module/userApi";
// import StoreApi from "@module/StateApi";
import Uts from "@module/Uts";
import Filter from "@module/Filter";

export default class userB extends React.Component {
    constructor(props) {
        console.log("userB.js init");
        console.log("constructor");
        super(props);
        this.state = {
            userB: {
                name: "tommy"
            }
        };
        let _self = this;
        function updateState(value) {
            _self.setState({
                userB: value.user
            });
        }
        function updateUserName(value) {
            _self.setState({
                userName: value
            });
        }
        let cleanUserNameHook = StateApi.addStoreStateHook(
            "userName",
            updateUserName
        );

        // Uts.regHook(this, function(obj) {
        UserApi.addUserStateHook(updateState, "userB");
        // });
        /*(function(obj) {
            // global.runJs2 = function(value) {
            //     obj.setState(value);
            // };
            UserApi.addUserStateHook(function(value) {
                obj.setState(value);
            }, 'userB');
        })(this);*/
    }

    updateState(obj, value) {
        obj.setState(value);
    }

    componentDidMount() {
        console.log("userB.js mount");
    }

    componentWillUnmount() {
        console.log("componentWillUnmount");
    }

    componentDidUpdate() {
        console.log("userB.js update");
    }

    render() {
        return (
            <div>
                用户为：{this.state.userB.name}
                记录2为：{this.state.userName}
            </div>
        );
    }
}
